package com.easyfile.easyfilemaster.interceptor;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 接口拦截器
 * 打印请求信息
 * @author Chenpeman
 */
@Slf4j
public class NormalInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        String method = request.getMethod();
        String remoteAddr = request.getRemoteAddr();
        String queryString = request.getQueryString();
        Map<String, String[]> parameterMap = request.getParameterMap();
        log.info("*{}* IP[{}]==>URI[{}] #Query:{} #Params{}",method,remoteAddr,requestURI,queryString, JSONObject.toJSONString(parameterMap));
        return true;
    }
}
